package com.guangyunl.b_array;

import java.util.Random;

// 需求: 随机50个1~100之间的整数，统计偶数个数
public class Demo05TraEven {
    public static void main(String[] args) {
        // 创建Random对象
        Random rd = new Random();
        // 定义一个长度为50的数组存储整数
        int[] arr1 = new int[50];
        // 循环录入50个随机整数
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = rd.nextInt(100) + 1;
        }
        // 定义变量统计偶数个数
        int quantity = 0;
        for (int i = 0; i < arr1.length; i++) {
            if(arr1[i] % 2 == 0){
                System.out.println("arr1[" + i + "] = " + arr1[i]);
                quantity++;
            }
        }
        System.out.println("偶数个数为:" + quantity);
    }
}

/*
注意：数组的值为随机生成
 */
/*
arr1[1] = 42
arr1[2] = 62
arr1[6] = 42
arr1[10] = 48
arr1[12] = 50
arr1[14] = 8
arr1[17] = 64
arr1[19] = 26
arr1[21] = 68
arr1[24] = 68
arr1[27] = 26
arr1[28] = 30
arr1[32] = 8
arr1[34] = 10
arr1[35] = 84
arr1[36] = 46
arr1[37] = 36
arr1[39] = 66
arr1[41] = 4
arr1[43] = 18
arr1[45] = 40
arr1[47] = 22
arr1[48] = 48
偶数个数为:23
 */